package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.bean.ManBean;
import com.project.bean.RoomBean;
import com.project.mapper.IManMapper;
import com.project.mapper.IRoomMapper;
import com.project.service.IManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ManServiceImpl implements IManService {
    @Autowired
    private IManMapper manMapper;
    @Autowired
    private IRoomMapper roomMapper;
    @Override
    public void add(ManBean man, List<RoomBean> roomList) {
        manMapper.insert(man);
        manMapper.addRoomList(man.getId(),roomList);
    }

    @Override
    public void del(int id) {
        manMapper.del(id);
    }

    @Override
    public ManBean findById(int id) {
        ManBean man = manMapper.selectById(id);
        QueryWrapper<RoomBean> qw = new QueryWrapper<>();
        qw.eq("fk_manId",id);
        man.setRoomList(roomMapper.selectList(qw));

        return man;
    }
}
